package com.personal.kotlinmvptest.module

import android.os.Bundle
import android.os.Handler
import android.os.Message
import com.personal.kotlinmvptest.entity.Personal

/**
 * @Description
 *
 * @author taodq
 * @Date 2019-06-12.
 */
class MainPreserter(private val mView: MainContract.View) : MainContract.Presenter {

    init {
        mView.setPresenter(this)
    }

    private val mHandler: Handler = object : Handler() {
        override fun handleMessage(msg: Message?) {
            var personal = msg?.data?.get("personal") as Personal
            mView.showPersonal(personal)
        }
    }

    override fun loadPersonal() {
        var personal = Personal.Builder().setName("张无忌").setAge(18).create()
        var msg = Message.obtain()
        var bundle = Bundle()
        bundle.putSerializable("personal", personal)
        msg.data = bundle
        mHandler.sendMessageDelayed(msg, 3000)
    }

    override fun start() {
        loadPersonal()
    }

}